package com.kitty.web.controller;

import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.AnnualShopItem;
import com.kitty.web.system.onlinemall.service.IAnnualShopItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 周年卡Controller
 *
 * @author soul
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/system/annualShop")
public class PAnnualShopItemController extends BaseController {
    private String prefix = "system/annualShop";

    @Autowired
    private IAnnualShopItemService IAnnualShopItemService;


    @GetMapping()
    public String annualShop() {
        return prefix + "/annualShop";
    }

    /**
     * 查询周年卡列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AnnualShopItem AnnualShopItem) {
        startPage();
        List<AnnualShopItem> list = IAnnualShopItemService.selectAnnualShopItemList(AnnualShopItem);
        return getDataTable(list);
    }

    /**
     * 新增周年卡
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存周年卡
     */

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AnnualShopItem annualShopItem) {
        return toAjax(IAnnualShopItemService.insertAnnualShopItem(annualShopItem));
    }

    /**
     * 修改周年卡
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AnnualShopItem annualShop = IAnnualShopItemService.selectAnnualShopItemById(id);
        mmap.put("annualShop", annualShop);
        return prefix + "/edit";
    }

    /**
     * 修改保存周年卡
     */

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AnnualShopItem annualShopItem) {
        return toAjax(IAnnualShopItemService.updateAnnualShopItem(annualShopItem));
    }

    /**
     * 删除周年卡
     */

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(IAnnualShopItemService.deleteAnnualShopItemByIds(ids));
    }
}
